{include file="public/header"}
<body>
<fieldset class="layui-elem-field">
    <legend>代理商列表</legend>
    <div class="layui-field-box">
        <form id="seachForm" method="" action="">
            <div class="layui-inline">
                <label class="layui-form-label">代理商姓名</label>
                <div class="layui-input-inline">
                    <input type="text" name="agent_name" value="" placeholder="如：和诚" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">按电话</label>
                <div class="layui-input-inline">
                    <input type="text" name="phone" value="" autocomplete="off" class="layui-input">
                </div>
            </div>
            <span id="seach" class="layui-btn layui-btn-normal"><i class="layui-icon">&#xe615;</i> 按条件收索</span>
        </form>

        <table class="layui-table" lay-even>
            <thead>
                <tr>
                    <th>Id</th>
                    <th>代理商姓名</th>
                    <th>电话</th>
                    <th>代理商数量</th>
                    <th>上级代理商</th>
                    <th>代理商余额</th>
                    <th>账户状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody  id="searchContent">
                    {volist name="list" id="vo"}
                        <tr>
                            <td>{$vo['id']}</td>
                            <td>{$vo['name']}</td>
                            <td>{$vo['mobile']}</td>
                            <td>{$vo['agent_num']}</td>
                            <td>{$vo['uper_name']}</td>
                            <td>{$vo['account']}</td>
                            <td>
                                {if condition="$vo['status'] == 0"}
                                    <span style="border-radius: 2px;background-color: #FF5722;padding:5px 10px;color: #ffffff">禁用</span>
                                    {else /}
                                    <span style="border-radius: 2px;background-color: #5FB878;padding:5px 10px;color: #ffffff">正常</span>
                                {/if}
                            </td>
                            <td>
                                <span onclick="edit({$vo['id']})" class="layui-btn layui-btn-normal">编辑</span>
                                <span onclick="search({$vo['id']})" class="layui-btn layui-btn-danger">删除</span>
                            </td>
                        </tr>
                    {/volist}
                </tbody>
        </table>
    </div>
</fieldset>


{include file="public/footer"}
    <script>
        layui.use(['layer'], function() {});

        function edit(id) {
            layer.open({
                type: 2,
                area: ['90%', '90%'],
                maxmin: true,
                content: '/agent/agent/edit/id/'+id
            });
        }
        function search(id) {
            layer.confirm('你确定要删除该代理商么?', {
                btn: ['确定','取消'] //按钮
            }, function(){
                var params  = {
                    url: '{:url("del")}',
                    data: {id:id},
                    type: 'post',
                    sCallback:function(res){
                        layer.msg(res.msg,{time:1800},function(){
                            location.reload();
                        });
                    }
                };
                common.request(params);
            });
        }

        $('#seach').on('click', function () {
            var params  = {
                url : "{:url('agent/agent/index')}",
                data: $("#seachForm").serialize(),
                type: 'post',
                sCallback:function(res){
                    var travelHtml = [];
                    for (var i=0; i < res.data.length; i++) {
                        var id = res.data[i]["id"];
                        travelHtml +='<tr> ' + '<td>'+(i+1)+'</td> ' +
                                '<td>'+res.data[i]["name"]+'</td> ' +
                                '<td>'+res.data[i]["mobile"]+'</td> ' +
                                '<td>'+res.data[i]["agent_num"]+'</td> ' +
                                '<td>'+res.data[i]["uper_name"]+'</td> ' +
                                '<td>'+res.data[i]["account"]+'</td> ' +
                                '<td>' +
                                '{if condition="'+ res.data[i][status] + ' === 0"} ' +
                                '<span style="border-radius: 2px;background-color: #FF5722;padding:5px 10px;color: #ffffff">禁用</span>' +
                                '{else /} ' +
                                '<span style="border-radius: 2px;background-color: #5FB878;padding:5px 10px;color: #ffffff">正常</span>' +
                                '{/if} ' +
                                '</td> ' +
                                '<td> ' +
                                '<span onclick="edit('+ id +')"  class="layui-btn edit1 layui-btn-normal">编辑</span>' +
                                '<span onclick="search('+ id +')" class="layui-btn layui-btn-danger confirm">删除</span> ' +
                                '</td> ' + '</tr>';
                    };
                    $('#searchContent').html(travelHtml);
                }
            };
            common.request(params);
        });
    </script>
</body>
</html>